<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="models.Course"%>
<%@page import="models.User"%>
<%@page import="service.UserDao"%>
<%@page import="org.hibernate.Session"%>
<%@page import="service.HibernateUtil"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link href="style/tutor.css" type="text/css" rel="Stylesheet">
        <!-- include jQuery Library From Google Code -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>

        <script type="text/javascript">
            $(document).ready(function(){
                $("#floatingMenu").click(function () {
                    $('#floatingMenuContent').slideToggle();
                });
             
                $("#showAnnouncement").click(function(){
                    $('#announcement').show();   
                    $('#allAnnouncements').hide();   
                });
                
                $("#cancelAnnouncement").click(function(){
                    $('#announcement').hide(); 
                    $('#allAnnouncements').show(); 
                });
                
                $("#closeAnnouncement").click(function(){
                    $('#announcementDetails').hide(); 
                });
                
            });
        </script>

        <jsp:useBean id="inhoud" scope="application" class="models.Bean" />   
        <jsp:setProperty name="inhoud" property="language" value="<%= models.Bean.getLanguage() %>" />
            
        
        <title>
            Three 2 Learn
        </title>
    </head>
    <body>       
        <div id="wrapper">
            
            <jsp:include page="sidebar.jsp"/>
            <div id="right">
                <jsp:include page="courseDescriptionList.jsp"/>              

                <h1>
                    <jsp:setProperty name="inhoud" property="key" value="AgendaManager" />
                    <jsp:getProperty name="inhoud" property="key" />
                </h1>
                <h2>
                    <jsp:setProperty name="inhoud" property="key" value="SelectACourse" />
                    <jsp:getProperty name="inhoud" property="key" />
                </h2>
                <table width="100%">
                    <tr>
                        <c:choose>             
                            <c:when test="${not empty courses}">
                                <c:forEach var="course" items="${courses}" varStatus="loop">
                                    <c:if test="${not loop.first and loop.index % 3 == 0}">
                                    </tr></tr>
                                </c:if>
                                <td width="20%">
                                    <a href="/agenda?sc=${course.getCourseID()}">${course.getName()}</a>
                                </td>
                            </c:forEach>

                        </c:when>
                        <c:otherwise>
                            <jsp:setProperty name="inhoud" property="key" value="NoCoursesAssigned" />
                            <jsp:getProperty name="inhoud" property="key" />
                        </c:otherwise>
                    </c:choose>
                    </tr>
                </table>

                <c:if test="${not empty selectedAnnouncement}"> 
                    <div id="announcementDetails">
                        <h2>
                            <jsp:setProperty name="inhoud" property="key" value="AnnouncementDetails" />
                            <jsp:getProperty name="inhoud" property="key" />
                        </h2>
                        <table width="100%">
                            <th colspan="2"> 
                                <jsp:setProperty name="inhoud" property="key" value="Announcement" />
                                <jsp:getProperty name="inhoud" property="key" />
                                : <b>${selectedAnnouncement.title}</b>
                                <a class="button float" href="#" id="closeAnnouncement">
                                    <jsp:setProperty name="inhoud" property="key" value="CloseAnnouncement" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                </a>
                            </th>
                            <tr >
                                <td class="darker"><b>
                                        <jsp:setProperty name="inhoud" property="key" value="Content" />
                                        <jsp:getProperty name="inhoud" property="key" />:</b>
                                </td><td>${selectedAnnouncement.content}</td>
                            </tr>
                            <tr >
                                <td class="darker"><b>On:</b></td><td> ${selectedAnnouncement.announcementDate}</td>
                            </tr>
                        </table>
                    </div>
                </c:if>

                <c:if test="${not empty selectedCourse}">
                    <h2><jsp:setProperty name="inhoud" property="key" value="AgendaOf" />
                        <jsp:getProperty name="inhoud" property="key" />
                        ${selectedCourse.name}</h2>

                    <table id="announcement" width="100%">
                        <form action="/agenda" method="post">
                            <th colspan="2">
                                <jsp:setProperty name="inhoud" property="key" value="NewAnnouncement" />
                                <jsp:getProperty name="inhoud" property="key" />
                                <a class="button float" href="#" id="cancelAnnouncement">
                                    <jsp:setProperty name="inhoud" property="key" value="CancelAnnouncement" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                </a>
                            </th>                            
                            <tr><td>
                                    <jsp:setProperty name="inhoud" property="key" value="Title" />
                                    <jsp:getProperty name="inhoud" property="key" />    
                                </td><td><input type="text" size="100%" name="title"/></td></tr>
                            <tr><td width="100px">
                                    <jsp:setProperty name="inhoud" property="key" value="Content" />
                                    <jsp:getProperty name="inhoud" property="key" />    
                                </td>
                                <td><textarea name="content">
                                    </textarea></td>
                            </tr>
                            <input type="hidden" name="author" value="28"/>
                            <input type="hidden" name="course" value="${selectedCourse.courseID}"/>
                            <tr><td colspan="2"><input type="submit" value="add"/></td></tr>
                        </form>
                    </table>

                    <table  id="allAnnouncements" width="100%">
                        <th colspan="3">
                            <jsp:setProperty name="inhoud" property="key" value="AllAnnouncements" />
                            <jsp:getProperty name="inhoud" property="key" />
                            <a class="button float" href="#" id="showAnnouncement">
                                <jsp:setProperty name="inhoud" property="key" value="MakeAnnouncement" />
                                <jsp:getProperty name="inhoud" property="key" />
                            </a>
                        </th>
                        <tr class="darker"><td colspan="3"><p>
                                    <jsp:setProperty name="inhoud" property="key" value="ClickAnnouncement" />
                                    <jsp:getProperty name="inhoud" property="key" />
                                </p></td></tr>
                        <tr>
                            <c:choose>
                                <c:when test="${not empty announcements}">
                                    <c:forEach var="tempAnnouncement" items="${announcements}" varStatus="loop">
                                        <c:if test="${not loop.first and loop.index % 3 == 0}">
                                        </tr><tr>
                                        </c:if>
                                        <td width="33.33%">
                                            <a href="/agenda?sc=${selectedCourse.courseID}&sa=${tempAnnouncement.getAnnouncementId()}">${tempAnnouncement.getTitle()}</a>
                                        </td> 
                                    </c:forEach>
                                </c:when>
                                <c:otherwise>
                                    <td colspan="3">
                                        <jsp:setProperty name="inhoud" property="key" value="NoAnnouncements" />
                                        <jsp:getProperty name="inhoud" property="key" />
                                    </td> 
                                </c:otherwise>
                            </c:choose>
                        </tr> 
                    </table>
                </c:if>

            </div>
        </div>
    </body>
</html>
